/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.maternity.classes.dao;

import br.com.maternity.classes.entity.Exame;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Gattini
 */
public class ExameDAO extends GenericDAO<Exame> {

    private static Exame instance = new Exame();

    public ExameDAO() {
        super(instance);
    }

    @Override
    public List<GenericDAOField> listFields() {
        List l = new ArrayList<GenericDAOField>();

        l.add(new GenericDAOField(
                "Id", "setId", "getId", Integer.class, true, GenericDAOFieldPrimaryKey.IDENTITY));
        l.add(new GenericDAOField(
                "Descricao", "setDescricao", "getDescricao", String.class));

        return l;
    }

    @Override
    public String tableName() {
        return "Exame";
    }
    
    public List<Exame> selectAll(){
        return super.selectList("SELECT * FROM " + tableName());
    }

    public Exame getById(Integer id) {
        try {
            String query = "SELECT * FROM " + tableName() + " WHERE Id = ?";
            PreparedStatement ps = super.getPreparedStatement(query);
            ps.setInt(1, id);
            return select(ps);
        } catch (Exception ex) {
            return null;
        }
    }
}
